﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WISD.CarFriend.Model;

namespace WISD.CarFriend.Web.Admin.Module.AdvertisementManage
{
    public partial class Edit : Utility.BasicPage
    {
        #region 字段
        private int m_Id;
        private WISD.CarFriend.BLL.Web.AdvertisementManageModule m_AdManageModuleBLL
            = new BLL.Web.AdvertisementManageModule();
        #endregion


        #region 事件
        /// <summary>
        /// 加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!int.TryParse(Request.Params["id"].ToString(), out this.m_Id))
                {
                    base.ShowMessageBox(350, 230, "错误提示", "<b>出现错误啦！</b>您要修改的信息不存在或参数不正确。", "back", "Error");
                    return;
                }

                if (!Page.IsPostBack)
                {
                    // 验证权限
                    base.CheckPermission("AdvertisementManage_Edit");

                    this.Show();
                }
            }
            catch (Exception exception)
            {
                base.ShowMessageBox(350, 230, "错误提示", "<b>出现错误啦！</b>" + exception.Message.ToString(), "back", "Error");
            }
        }


        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                this.Save();
            }
            catch (Exception exception)
            {
                base.ShowMessageBox(350, 230, "错误提示", "<b>出现错误啦！</b>" + exception.Message.ToString(), "back", "Error");
            }
        }
        #endregion


        #region 方法
        /// <summary>
        /// 显示要修改的内容
        /// </summary>
        private void Show()
        {
            T_CF_Web_AdvertisementInfo adInfo = this.m_AdManageModuleBLL.GetAdvertisementByID(this.m_Id);
            this.txtTitle.Text = adInfo.Title;
            this.txtImagePath.Text = adInfo.ImagePath;
            this.txtURL.Text = adInfo.URL;
        }


        /// <summary>
        /// 保存修改的内容
        /// </summary>
        private void Save()
        {
            this.m_AdManageModuleBLL.UpdateAdvertisement(this.m_Id, this.txtTitle.Text.Trim(), this.txtImagePath.Text.Trim(),
                base.AddHttp(this.txtURL.Text.Trim()), int.Parse(Session["UserID"].ToString()));
            base.ShowMessageBox("内容编辑成功啦！", "List.aspx", "Success");
        }

        #endregion
    }
}